$(function () {
    var basePath="http://localhost:8085/mysite0621" ;
    $("#categorySelected").click(function () {
        $.ajax({
            url:basePath+"/GetCategoryListServlet",
            type:"get",
            dataType:"json",
            success:function (result) {
                var content ;
                $.each(result,function (index,item) {
                    content+="<option value="+item.id+">"+item.name+"</option>";
                    console.log(item,name);
                });
                $(this).html(content);
            },
            error:function () {
                console.log("ajax交互失敗");
            }
        });
    });
    $("#categorySelected option:selected").change(function () {
        var categoryId=$(this).val();
        $.ajax({
            url:basePath+"/GetNewsListPagesByCategoryIdAjaxServlet",
            data:{
                "categoryId":categoryId,
                "pageNo":1
            },
            type:"get",
            dataType:"json",
            success:function (result) {
                console.log("返回字符串為"+result);
                var content="";
                $.each(result,function (index,item) {
                    content+="<tr>";
                    content+=" <td><a href=" + basePath + "/jsp/pages/newsDetail.jsp?newsId"+ item.id +" " +
                        "target=\"_blank\">"+item.title+"</a></td>";
                    content+="<td>"+item.createBy+"</td>";
                    content+="<td>"+item.createDate+"</td>";
                    content+="<td><a href="+basePath+"/jsp/admin/news/newsModify.jsp?newsId="+item.id+
                    ">修改</a>" +
                        "<a href=\"javascript:if(confirm('确认是否删除新闻？')) location='<%=request.getContextPath()%>/DeleteNewsServlet?newsId=<%=news.getId()%>'\">删除</a>\n" +
                        "</td>";
                    content+="<tr>";
                });
                $("#tbodyId").html(content);
            },
            error:function () {
                window.alert("ajax交互失敗");
            }
        });
    });
});